/*
 * @ Auth 愫愫小洁
 * @ Update 2024-11-30 T 6-27
 * Copyright (c) 2024.  缔鑫网络科技
 */
import { get, post, deletes, put } from '../utils/http'
import { setToken } from '../utils/auth'
import request from '../utils/request';  // 假设您使用了 axios 或类似的请求库

//  用户登录
export const _apiLogin = async (params) => {
    const response = await post('/auth/login', params)
    if (response.token) {
        setToken(response.token)
    }
    return response
}
// 获取验证码图片
export const _apiCaptcha = () => get('/VerifyCode')
//修改密码
export const _apiChangePassword = (params) => {
  return request({
    url: '/account/manager/password',
    method: 'PUT',
    data: params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  })
}
//获取当前用户信息
export const _apiCurrentUser = () => {
  return request({
    url: '/account/manager/info',
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};

//--------------------------------------------------首页----------------------------------------------------------------------------

//获取会员注册统计
export const _apiMemberRegisterCount = () => {
  return request({
    url: '/admin/report/member/register/count',
    method: 'GET',
    headers: {  
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取会员注册统计数量
export const _apiMemberRegisterview = () => {
  return request({
    url: '/admin/member/view/report',
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取会员注册分页
export const _apiMemberRegisterPage = (params) => {
  return request({
    url: '/admin/report/member/register/list',
    method: 'GET',
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取会员消费统计
export const _apiMemberConsumeCount = () => {
  return request({
    url: '/admin/report/member/amount/count',
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取订单金额统计
export const _apiOrderAmountCount = () => {
  return request({
    url: '/admin/report/order/amount/count',
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取订单总记录数量
export const _apiOrderTotalCount = (params) => {
  return request({
    url: '/admin/order/view/count',
    method: 'GET',
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取退款退货统计
export const _apiRefundCount = (params) => {
  return request({
    url: `/admin/order/refund/${params.type}`,
    method: 'GET',
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取商品销售统计
export const _apiProductSaleCount = () => {
  return request({
    url: '/admin/report/order/goods/count',
    method: 'GET',  
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取待审核商品
export const _apiProductAudit = () => {
  return request({
    url: '/admin/shop/goods/view/count',
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取待审核会员
export const _apiMemberAudit = () => {
  return request({
    url: '/admin/member/view/count',
    method: 'GET',
  });
};
//获取待审核商户
export const _apiMerchantAudit = () => {
  return request({
    url: '/admin/merchant/view/count',
    method: 'GET',
  });
};



//获取角色列表
export const _apiRoleList = () => {
  return request({
    url: '/admin/manager/role',
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取订单列表
export const _apiOrderList = (params) => {
  return request({
    url: '/admin/order',
    method: 'GET',
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取会员列表
export const _apiMemberList = (params) => {
  return request({
    url: '/admin/member',
    method: 'GET',
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取会员信息
export const _apiMemberInfo = (params) => {
  return request({
    url: `/admin/member/${params.userId}`,
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//会员充值
export const _apiMemberRecharge = (params, config) => {
  return request({
    url: '/admin/member/recharge',
    method: 'POST',
    data: params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
      'Content-Type': 'application/json'
    },
    ...config
  });
};
//获取充值审核列表
export const _apiRechargeAuditList = () => {
  return request({
    url: '/admin/member/recharge',
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//审核充值
export const _apiRechargeAudit = (params) => {
  return request({
    url: `/admin/member/recharge`,
    method: 'PUT',
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};

//获取支付方式
export const _apiPayType = () => {
  return request({
    url: `/admin/payment`,
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取储值列表
export const _apiRechargeList = (params) => {
  return request({
    url: '/admin/member/recharge',
    method: 'GET',
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取积分列表
export const _apiIntegralList = (params) => {
  return request({
    url: '/admin/member/point',
    method: 'GET',
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取优惠券列表
export const _apiCouponList = (params) => {
  return request({
    url: `/admin/shop/coupon`,
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//获取账号列表
export const _apiAccountList = (params) => {
  return request({
    url: '/admin/manager',
    method: 'GET',
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//添加账号
export const _apiAccountAdd = (params) => {
  return request({
    url: '/admin/manager',
    method: 'POST', 
    data: params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//根据userid删除账号
export const _apiAccountDelete = (params) => {
  return request({
    url: `/admin/manager/${params.userId}`,
    method: 'DELETE',
  });
};
//修改当前账号密码
export const _apiAccountUpdatePassword = (params) => {
  return request({
    url: '/account/member/password',
    method: 'PUT',
    data: params,
  });
};

//根据id获取订单详情
export const _apiOrderDetail = (params) => {
  return request({
    url: `/admin/order/${params.id}`,
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};
//根据id修改订单收货人信息备注等
export const _apiOrderUpdate = (params) => {
  const { id, acceptName, mobile, address } = params;
  
  // 创建 FormData 对象
  const formData = new FormData();
  formData.append('acceptName', acceptName);
  formData.append('mobile', mobile);
  formData.append('address', address);

  return request({
    url: `/admin/order/${id}`,
    method: 'PUT',
    data: formData,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,
      'Content-Type': 'multipart/form-data'  // FormData 格式
    }
  });
};

//获取商品列表
export const _apiProductList = (params) => {
  return request({
    url: '/admin/shop/goods',
    method: 'GET',
    params,
    headers: {
      'Authorization': `Bearer ${localStorage.getItem('token')}`,  // 添加 token
    }
  });
};


